import requests
import re
import sys
import os


def fetch(url):
    response = requests.get(url)
    if response.ok:
        html = response.text
    else:
        html = ''
    return html


def parse(html):
    pat = r'(Python .*)</a>.*\n.*date..(.*)</span'
    return re.findall(pat, html)


def store(data, path):
    with open(path, 'w') as f:
        for a, b in data:
            f.write('%s,%s\n' % (a, b))


if __name__ == '__main__':
    if len(sys.argv) != 3:
        print('usage: %s url out' % os.path.basename(sys.argv[0]))
        exit(1)

    url = sys.argv[1]
    out_path = sys.argv[2]
    html = fetch(url)
    data = parse(html)
    store(data, out_path)
